<?php
namespace Components\Trade\First;

class Adapter {
	static private $instance = [];

	public function __construct($config = []) {
		
	}

	static private function newClassName($key, $class_name) {
		if(isset(self::$instance[$key]) && !empty(self::$instance[$key])) {
			return self::$instance[$key];
		}

		$className = __NAMESPACE__ . '\\' . $class_name;
		if(!class_exists($className)) {
			throw new \Exception($className . ' is non-existent.');
		}

		return new $className();
	}

	static public function getModelInstance() {
		return self::$instance['model'] = new Model();
	}

	static public function getBuyServiceInstance($parameter = []) {
		return self::newClassName('buy_service', 'Buy\\Service');
	}

	static public function getBuyLogicInstance($parameter = []) {
		return self::newClassName('buy_logic', 'Buy\\Logic');
	}

	static public function getSellServiceInstance($parameter = []) {
		return self::newClassName('sell_service', 'Sell\\Service');
	}

	static public function getSellLogicInstance($parameter = []) {
		return self::newClassName('sell_logic', 'Sell\\Logic');
	}
	
}
